﻿namespace SinclairCC.AppVSuite.DuplicateRootDetector
{
    using System;
    /*
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    */

    public static class Shared
    {
        /// <summary>
        /// Gets the path of the stylesheet repository folder.
        /// </summary>
        public static string StylesheetRepositoryFolderPath
        {
            get
            {
                // Construct the path of the repository folder.
                string folderPath;
                folderPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData), "Sinclair Community College");
                folderPath = System.IO.Path.Combine(folderPath, "App-V Suite");
                folderPath = System.IO.Path.Combine(folderPath, "Duplicate Root Detector");
                folderPath = System.IO.Path.Combine(folderPath, "Stylesheets");

                return folderPath;
            }
        }

        /// <summary>
        /// Prepares the stylesheet repository folder.
        /// </summary>
        public static void PrepareStylesheetRepository()
        {
            string folderPath = StylesheetRepositoryFolderPath;

            if (!System.IO.Directory.Exists(folderPath))
            {
                System.IO.Directory.CreateDirectory(folderPath);
            }

            // If the local repository folder exists and does not contain the default XSL file, make a copy
            // of the default stylesheet file in the repository folder.
            if (System.IO.Directory.Exists(folderPath))
            {
                /*System.IO.DirectoryInfo repositoryDirInfo = new System.IO.DirectoryInfo(folderPath);*/
                if (!System.IO.File.Exists(DefaultStyleSheetPath))
                {
                /*if (System.IO.Directory.GetFiles(folderPath, "*.xsl", System.IO.SearchOption.TopDirectoryOnly).Length == 0)
                {
                    string filePath = System.IO.Path.Combine(folderPath, "Default Stylesheet.xsl");*/
                    System.IO.StreamWriter writer = new System.IO.StreamWriter(DefaultStyleSheetPath, false);
                    writer.Write(DuplicateRootDetector.Properties.Resources.default_stylesheet);
                    writer.Close();
                    writer.Dispose();
                }
            }
        }

        public static string DefaultStyleSheetPath
        {
            get { return System.IO.Path.Combine(StylesheetRepositoryFolderPath, "Default Stylesheet.xsl"); }
        }
    }
}
